package com.ccut.lc.controller;


import com.ccut.lc.model.Product;
import com.ccut.lc.model.ProductType;
import com.ccut.lc.model.QueryVo;
import com.ccut.lc.service.ProductTypeService;
import com.ccut.lc.utils.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("productType")
public class ProductTypeController {
	@Resource
	private ProductTypeService productListService;
	@RequestMapping("add")
	public String addProduct(Product product){
		//productListService.addProduct(product);
		return "SCUESS";
	}
	@RequestMapping("list")
	public String selProductList(QueryVo queryVo, Model model){
		Page<ProductType> page = productListService.selProductType(queryVo);
		model.addAttribute("page",page);
		return "product/productType";
	}

	@RequestMapping("welcome")
	public String welcome(){
		return "system/welcome";
	}



	@RequestMapping("edit")
	@ResponseBody
	public ProductType edit(Integer id){
		ProductType productType = productListService.findProductTypeByID(id);
		return productType;
	}

	@RequestMapping("update")
	@ResponseBody
	public String update(ProductType productType){
		String msg = "1";
		try {
			productListService.updateProductType(productType);
			msg = "0";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return msg;
	}
	@RequestMapping("delete")
	@ResponseBody
	public String delete(Integer id){
		String msg = "1";
		try {
			productListService.deleteProductType(id);
			msg = "0";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return msg;
	}
	@RequestMapping("addProduct")
	@ResponseBody
	public String add(ProductType product){
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MMM-ddd hhh:mmm:sss");
		String format = sf.format(new Date());
		String msg = "1";
		try {
			productListService.addProduct(product);
			msg = "0";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return msg;
	}

	@RequestMapping("myTag")
	public String myTage() {
		return "myTag";
	}

}
